package org.example.server.search.doc;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.List;

@Document(indexName = GoodsDOC.INDEX_NAME)
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown=true)
public class GoodsDOC extends BaseDOC{
    public static final String INDEX_NAME = "goods";

    @Id
    @Field(type = FieldType.Keyword, index = false)
    private Long id;

    /**
     * 商品标题
     */
    @Field(type = FieldType.Text,analyzer ="ik_smart",searchAnalyzer = "ik_smart")
    private String title;

    /**
     * 商品子标题
     */
    @Field(type = FieldType.Text,analyzer ="ik_smart",searchAnalyzer = "ik_smart")
    private String subTitle;

    /**
     * 商品状态
     */
    @Field(type = FieldType.Keyword)
    private String status;
    /**
     * image
     */
    @Field(type = FieldType.Keyword, index = false)
    private String mainImage;
    /**
     * 分类
     */
    @Field(type = FieldType.Nested)
    private Category category;
    /**
     * sku列表
     */
    @Field(type = FieldType.Nested)
    private List<Sku> skus;
    /**
     * tags
     */
    @Field(type = FieldType.Nested)
    private List<Tag> tags;

    /**
     * params
     */
    @Field(type = FieldType.Nested)
    private List<Param> params;

    @Getter
    @Setter
    public static class Category extends BaseDOC{
        /**
         * 分类名称
         */
        @Field(type = FieldType.Keyword, index = false)
        private Long id;

        /**
         * 分类名称
         */
        @Field(type = FieldType.Keyword)
        private String categoryName;

        /**
         * 分类路径
         */
        @Field(type = FieldType.Text,analyzer ="ik_smart",searchAnalyzer = "ik_smart")
        private String path;

        /**
         * 分类是否展示
         */
        @Field(type = FieldType.Boolean)
        private Boolean isDisplay;

        /**
         * 分类排序
         */
        @Field(type = FieldType.Integer)
        private Integer sort;

        /**
         * 单位
         */
        @Field(type = FieldType.Text, index = false)
        private String unit;
    }

    @Getter
    @Setter
    public static class Tag extends BaseDOC{
        /**
         * tagID
         */
        @Field(type = FieldType.Keyword,index = false)
        private Long id;

        @Field(type = FieldType.Keyword, index = false)
        private Long goodsId;
        /**
         * tag类型
         */
        @Field(type = FieldType.Keyword)
        private String type;
    }

    @Getter
    @Setter
    public static class Sku extends BaseDOC{
        @Field(type = FieldType.Keyword, index = false)
        private Long id;

        @Field(type = FieldType.Keyword, index = false)
        private Long goodsId;
        /**
         * image
         */
        @Field(type = FieldType.Keyword, index = false)
        private String image;
        /**
         * sku编码
         */
        @Field(type = FieldType.Keyword)
        private String skuCode;
        /**
         * 规格名称
         */
        @Field(type = FieldType.Text,index = false)
        private String name;
        /**
         * 规格值
         */
        @Field(type = FieldType.Text,analyzer ="ik_smart",searchAnalyzer = "ik_smart")
        private String description;
        /**
         * 销售价格
         */
        @Field(type = FieldType.Long)
        private Long price;
        /**
         * 划线价格
         */
        @Field(type = FieldType.Long)
        private Long linePrice;
        /**
         * 成本价格
         */
        @Field(type = FieldType.Long)
        private Long costPrice;
        /**
         * 库存
         */
        @Field(type = FieldType.Long)
        private Long stock;
        /**
         * sku状态
         */
        @Field(type = FieldType.Keyword)
        private String status;
    }

    @Getter
    @Setter
    public static class Param extends BaseDOC{
        @Field(type = FieldType.Keyword, index = false)
        private Long id;
        /**
         * 商品ID
         */
        @Field(type = FieldType.Keyword, index = false)
        private Long goodsId;
        /**
         * 参数名称
         */
        @Field(type = FieldType.Keyword, index = false)
        private String name;
        /**
         * 参数值
         */
        @Field(type = FieldType.Text,analyzer ="ik_smart",searchAnalyzer = "ik_smart")
        private String description;
    }

}